package com.middlegroup.subjectpay.entity;

import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import com.middlegroup.common.enums.AesKeyUtil;
import com.middlegroup.common.mybatisplus.BaseEntity;
import com.middlegroup.common.utils.AesUtils;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
 * <p>
 * 协议绑卡成功记录表
 * </p>
 *
 * @author chengweiwei123
 * @since 2019-01-24
 */
@TableName("t_third_protocol_bind_card")
@Data
public class ThirdProtocolBindCard extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /**
     * 主体code
     */
    @TableField("subject_code")
    private String subjectCode;
    /**
     * 通道code
     */
    @TableField("channel_code")
    private String channelCode;
    /**
     * 签约卡号，密文
     */
    @TableField("card_no")
    private String cardNo;
    /**
     * 银行预留手机号，密文
     */
    private String phone;
    /**
     * 姓名，密文
     */
    private String name;
    /**
     * 身份证号，密文
     */
    @TableField("id_card")
    private String idCard;
    /**
     * 协议编号
     */
    @TableField("protocol_no")
    private String protocolNo;
    /**
     * 1：签约成功，2：签约失效（签约后失效）
     */
    private Integer status;

    /**
     * 解密
     *
     * @throws Exception
     */
    public void GetDecryptAll(String askey) throws Exception {
        this.cardNo = AesUtils.decrypt(cardNo, askey);
        this.idCard = AesUtils.decrypt(idCard, askey);
        this.name = AesUtils.decrypt(name, askey);
        this.phone = AesUtils.decrypt(phone, askey);
    }

    /**
     * 加密
     *
     * @param aeskey
     * @throws Exception
     */
    public void SetEncryptAll(String aeskey) throws Exception {
        if (StringUtils.isNotBlank(cardNo)) {
            this.cardNo = AesUtils.encrypt(cardNo, aeskey);
        }
        if (StringUtils.isNotBlank(idCard)) {
            this.idCard = AesUtils.encrypt(idCard, aeskey);
        }
        if (StringUtils.isNotBlank(name)) {
            this.name = AesUtils.encrypt(name, aeskey);
        }
        if (StringUtils.isNotBlank(phone)) {
            this.phone = AesUtils.encrypt(phone, aeskey);
        }
    }
}
